package com.ruoyi.project.system.main.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.system.main.domain.EchartsDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.main.mapper.ScoreMainMapper;
import com.ruoyi.project.system.main.domain.ScoreMain;
import com.ruoyi.project.system.main.service.IScoreMainService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 得分主Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-02-22
 */
@Service
public class ScoreMainServiceImpl implements IScoreMainService 
{
    @Autowired
    private ScoreMainMapper scoreMainMapper;

    /**
     * 查询得分主
     * 
     * @param id 得分主ID
     * @return 得分主
     */
    @Override
    public ScoreMain selectScoreMainById(Long id)
    {
        return scoreMainMapper.selectScoreMainById(id);
    }

    /**
     * 查询得分主列表
     * 
     * @param scoreMain 得分主
     * @return 得分主
     */
    @Override
    public List<ScoreMain> selectScoreMainList(ScoreMain scoreMain)
    {
        return scoreMainMapper.selectScoreMainList(scoreMain);
    }

    /**
     * 新增得分主
     * 
     * @param scoreMain 得分主
     * @return 结果
     */
    @Override
    public int insertScoreMain(ScoreMain scoreMain)
    {
        scoreMain.setCreateTime(DateUtils.getNowDate());
        scoreMain.setCreateBy(ShiroUtils.getLoginName());
        return scoreMainMapper.insertScoreMain(scoreMain);
    }

    /**
     * 修改得分主
     * 
     * @param scoreMain 得分主
     * @return 结果
     */
    @Override
    public int updateScoreMain(ScoreMain scoreMain)
    {
        scoreMain.setUpdateTime(DateUtils.getNowDate());
        scoreMain.setUpdateBy(ShiroUtils.getLoginName());
        return scoreMainMapper.updateScoreMain(scoreMain);
    }

    /**
     * 删除得分主对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteScoreMainByIds(String ids)
    {
        return scoreMainMapper.deleteScoreMainByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除得分主信息
     * 
     * @param id 得分主ID
     * @return 结果
     */
    @Override
    public int deleteScoreMainById(Long id)
    {
        return scoreMainMapper.deleteScoreMainById(id);
    }

    /**
     * 查询全部
     * @param scoreMain
     * @return
     */
    @Override
    public List<ScoreMain> selectScoreMainAll(ScoreMain scoreMain) {
        return scoreMainMapper.selectScoreMainAll(scoreMain);
    }
    /**
     * 更新总分+
     * @param userId
     * @param score
     * @return
     */
    @Override
    public int updateScoreMainTotalScore(Long userId, Long score) {
        return scoreMainMapper.updateScoreMainTotalScore(userId,score);
    }
    /**
     * 更新总分-
     * @param userId
     * @param score
     * @return
     */
    @Override
    public int updateScoreMainTotalScoreMinus(Long userId, long score) {
        return scoreMainMapper.updateScoreMainTotalScoreMinus(userId,score);
    }

    /**
     * 查询echars  按每个街道的最近7天的分数
     * @return
     */
    @Override
    public List<EchartsDto> selectScoreByEcharts() {
        return scoreMainMapper.selectScoreByEcharts();
    }
}
